package com.lichao.tools.sql;

/**
 * @author: li chao
 * @Desc:
 * @create: 2025-02-11 11:56
 **/

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SqlFilterExtractor {

    public static void main(String[] args) {
        String sql = "select * from user where a2.user_namessscc  = '${name}' and uages  = ${ages}";
        String filterCondition = extractFilterCondition(sql);
    }

    public static String extractFilterCondition(String sql) {
        // Regular expression to match the pattern "column_name=${variable}"
//        Pattern pattern = Pattern.compile("\\b\\w+\\s*=\\s*\\$\\{\\w+\\}");
        String patt = "\\b\\w+(\\.\\w+)?\\s*=\\s*\\$\\{\\w+\\}";
        Pattern pattern = Pattern.compile(patt);
        Matcher matcher = pattern.matcher(sql);

        while (matcher.find()) {
            String columnName = matcher.group(); // 第一个捕获组，匹配列名
            System.out.println("Column Name: " + columnName);
        }
        return null;
    }
}